package com.example.ssm.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <E> Result<E> success(E data) {
        Result<E> result = new Result<>();
        result.setCode(0);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    //快速返回操作成功响应结果
    public static Result success() {
        Result result = new Result();
        result.setCode(0);
        result.setMsg("操作成功");
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    public static <E> Result<E> success1(int i, E data) {
        Result<E> result = new Result<>();
        result.setCode(i);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }
}
